/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UTIL;

import com.microsoft.sqlserver.jdbc.SQLServerDriver;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;

/**
 *
 * @author Nguyen Hoang Anh
 */

public class SqlDataAccessHelper {

    protected static String connectionString;
/**
 * get connection string
 *
 * @return
 */
    public static String getConnectionString() {
        try {
            connectionString = null;
//            File file = new File("QuanLyEmail.mdb");
//            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
//            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
//            Document doc = docBuilder.parse(file);
//            doc.getDocumentElement().normalize();
//            connectionString = doc.getFirstChild().getTextContent();

          // connectionString =  "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=QuanLyEmail.mdb";
            connectionString = ReadXML.getConnectString();

               
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return connectionString;
    }
    /**
     * connect to database
     * @return
     */
    public static Connection getConnection() {
        Connection connect = null;
        try {
            // Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            java.util.Properties prop = new java.util.Properties();
            prop.put("CharSet","UTF-8");
            //DriverManager.r6egisterDriver(new SQLServerDriver());
            connect = DriverManager.getConnection(getConnectionString());
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return connect;
    }   
}
